# 使用sqlalchemy对数据库进行增删改查
from sqlalchemy import create_engine, Column, BigInteger, String, DateTime, Integer
from sqlalchemy.orm import sessionmaker
# 1、创建引擎类
from sqlalchemy.orm import declarative_base, Session

engine = create_engine("mysql+pymysql://root:123456@localhost/biyesheji", pool_recycle=3600, echo=True)
Session = sessionmaker(engine)
# 2、创建所有模型类的父类
Base = declarative_base()


# 3、创建模型类
class User(Base):
    __tablename__ = 'user'

    def __init__(self, username, password):
        self.username = username
        self.password = password

    id = Column(BigInteger, primary_key=True, comment='主键')
    username = Column(String(64), nullable=False, comment='用户名')
    password = Column(String(128), comment='密码')
    lasttime = Column(DateTime, comment='最后一次登陆时间')





if __name__ == '__main__':
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)

    with Session(engine) as s:
        uu = [User(f'root0{i}', f'admin0{i}') for i in range(10)]
        s.add_all(uu)
        s.commit()


